package Games.PumpGame.Entities  
{
	import Framework.BaseEntity;
	import Framework.GameHelper;
	import Games.PumpGame.GameEntityType;
	
	/**
	 * ...
	 * @author Menno
	 */
	public class Connection extends BaseEntity
	{
		private var _entityA:BaseEntity;
		private var _entityB:BaseEntity;
				
		public function Connection(entityA:BaseEntity, entityB:BaseEntity) 
		{
			_entityA = entityA;
			_entityB = entityB;
			
			type = GameEntityType.CONNECTION;
		}
		
		public function isConnected(entity:BaseEntity):Boolean
		{
			if (GameHelper.compareObject(entity, entityA) || GameHelper.compareObject(entity, entityB))
			{
				return true;
			}
			return false;
		}
		
		public function getPowerPlant():PowerPlant
		{
			if (entityA.type == GameEntityType.POWERPLANT)
			{
				return entityA as PowerPlant;
			}
			
			if (entityB.type == GameEntityType.POWERPLANT)
			{
				return entityB as PowerPlant;
			}
			
			return null;
		}
		
		public function getPump():Pump
		{
			if (entityA.type == GameEntityType.PUMP)
			{
				return entityA as Pump;
			}
			
			if (entityB.type == GameEntityType.PUMP)
			{
				return entityB as Pump;
			}
			
			return null;			
		}
		
		public function get entityA():BaseEntity 
		{
			return _entityA;
		}
		
		public function set entityA(value:BaseEntity):void 
		{
			_entityA = value;
		}
		
		public function get entityB():BaseEntity 
		{
			return _entityB;
		}
		
		public function set entityB(value:BaseEntity):void 
		{
			_entityB = value;
		}
	}
	
}